<?php
/**
 *  View Interface
 *
 */
class Yz_View_Default
    extends Yz_View_Abstract
    implements Yz_View_Interface
{

    protected $cacheable;
    protected $charset = 'utf-8';
    protected $contentType;

    /**  set the rendered content type to text/plain
     *  @return chainable
     */
    public function asPlainText($charset=null)
    {
        if (null === $charset) {
            $charset = $this->charset;
        }
        $this->contentType = 'text/plain; charset=' . $charset;
        return $this;
    }

    /**  set the rendered content type to text/html
     *  @return chainable
     */
    public function asHTML($charset=null)
    {
        if (null === $charset) {
            $charset = $this->charset;
        }
        $this->contentType = 'text/html; charset=' . $charset;
        return $this;
    }

    /** [dis]allow the output to be cached
     *  @return chainable
     */
    public function setCacheable($cacheable=true)
    {
        $this->cacheable = $cacheable;
        return $this;
    }


    /**
     *  usually called by the response object which is supplied as argument
     *      in order to be notified by the view (set headers, status etc)
     *  @param Yz_HTTP_Response_Interface $rs
     *  @return string
     */
    public function render(Yz_HTTP_Response_Interface $rs)
    {
        debug();
        if (null !== $this->contentType) {
            $rs->setContentType($this->contentType);
        }
        if (null !== $this->cacheable) {
            $rs->setCacheable($this->cacheable);
        }
        return parent::render($rs);
    }

} // class
